package com.jdrx.sw.sewage.task;

import com.jdrx.sw.sewage.service.AlarmServiceImpl;
import com.jdrx.sw.sewage.service.GatherDevPoiServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
public class SaticScheduleTask {

    @Autowired
    private GatherDevPoiServiceImpl gatherDevPoiServiceImpl;
    @Autowired
    private AlarmServiceImpl alarmServiceImpl;

    /**
     * 站点所有工艺流程定时数据推送 username：gys_dataNode_stationId
     * 一：直接指定时间间隔，例如：5秒   二添加定时任务：@Scheduled(cron = "0/5 * * * * ?")
     */
    /*@Async("gysTasksExecutor")
    @Scheduled(fixedRate = 5000)
    public void gysTasks() {
        Map<String, WebSocketServiceImpl> clients = getClients(EWebSocketType.GYS.getKey());
        if (null == clients) return;

        for (Map.Entry<String, WebSocketServiceImpl> entry : clients.entrySet()) {
            String username = entry.getKey();
            try {
                String[] uStr = username.split("_");
                List<GroupDeviceDisplayVO> groupDeviceDisplayVOs = gatherDevPoiServiceImpl.findDisplayVOByStationId(Long.valueOf(uStr[2]), uStr[1]);
                if (null == groupDeviceDisplayVOs || groupDeviceDisplayVOs.size() <= 0) continue;

                JSONObject json = new JSONObject();
                json.put(EWebSocketType.MESSAGE.getKey(), groupDeviceDisplayVOs);
                json.put(EWebSocketType.TO.getKey(), username);// 给具体通道发送消息
                entry.getValue().onMessage(json.toString());
            } catch (BizException e) {
                e.printStackTrace();
            }
        }
    }*/

    /**
     * 站点所有工艺流程定时数据推送 username：gys_dataNode_stationId_processunitId
     * 一：直接指定时间间隔，例如：5秒   二添加定时任务：@Scheduled(cron = "0/5 * * * * ?")
     */
    /*@Async("gyTasksExecutor")
    @Scheduled(fixedRate = 5000)
    public void gyTasks() {
        Map<String, WebSocketServiceImpl> clients = getClients(EWebSocketType.GYS.getKey());
        if (null == clients) return;

        for (Map.Entry<String, WebSocketServiceImpl> entry : clients.entrySet()) {
            String username = entry.getKey();
            try {
                String[] uStr = username.split("_");
                List<DeviceDateDisplayVO> deviceDateDisplayVOs = gatherDevPoiServiceImpl.findDisplayVOByStationIdAndProcessunitId(Long.valueOf(uStr[2]), uStr[1], Long.valueOf(uStr[3]));
                if (null == deviceDateDisplayVOs || deviceDateDisplayVOs.size() <= 0) continue;

                JSONObject json = new JSONObject();
                json.put(EWebSocketType.MESSAGE.getKey(), deviceDateDisplayVOs);
                json.put(EWebSocketType.TO.getKey(), username);// 给具体通道发送消息
                entry.getValue().onMessage(json.toString());
            } catch (BizException e) {
                e.printStackTrace();
            }
        }
    }*/

    /**
     * 告警数统计定时数据推送 username：gjs_dataNode_stationId_userName
     * 一：直接指定时间间隔，例如：5秒   二添加定时任务：@Scheduled(cron = "0/5 * * * * ?")
     */
    /*@Async("gjsTasksExecutor")
    @Scheduled(fixedRate = 5000)
    public void gjsTasks() throws BizException {
        Map<String, WebSocketServiceImpl> clients = getClients(EWebSocketType.GJS.getKey());
        if (null == clients) return;

        for (Map.Entry<String, WebSocketServiceImpl> entry : clients.entrySet()) {
            String username = entry.getKey();
            String[] uStr = username.split("_");
            AlarmNumVO alarmNumVO = alarmServiceImpl.selectAllAlarmNum(uStr[3], uStr[1]);
            if (null == alarmNumVO) continue;

            JSONObject json = new JSONObject();
            json.put(EWebSocketType.MESSAGE.getKey(), alarmNumVO);
            json.put(EWebSocketType.TO.getKey(), username);// 给具体通道发送消息
            entry.getValue().onMessage(json.toString());
        }
    }*/
}